Page({
  data:{
    shuju:[],
    default_id:null,
  },
  onLoad:function(){
    var self=this;
    wx.showLoading();
    wx.request({
      url:"https://wx.ichelaba.com/htapi/index.php/user/address/index",
      data:{
        user_id:wx.getStorageSync("user_id")
      },
      method:"GET",
      success:function(res){
        console.log(res);
        self.setData({
          shuju:res.data.address_list
        })
        var have=null;
        for(var i=0;i<res.data.address_list.length;i++){
          if(res.data.address_list[i].is_default==1){
            have=1;
            self.data.carList=res.data.address_list[i].address_id;
          }
        }
        if(have==null){
          self.setData({
            default_id:null
          })
        }
        wx.hideLoading();
      }
    })
  },
  changeDefault_FN:function(e){
    this.data.default_id=e.detail.value;
    var self=this;
    wx.request({
      url:"https://wx.ichelaba.com/htapi/index.php/user/address/checkDefault",
      data:{
        id:e.detail.value,
        user_id:wx.getStorageSync("user_id")
      },
      method:"GET",
      success:function(res){
        console.log(res)
      }
    })
  },
  delete_FN:function(e){
    var delet_id=e.currentTarget.dataset.id;
    var self=this;
    console.log(wx.getStorageSync("user_id"),delet_id)
    wx.showModal({
      "title":"提示",
      "content":"确认删除",
      "success":function(e){
        if(e.confirm){
          wx.showLoading();
          wx.request({
            url:"https://wx.ichelaba.com/htapi/index.php/user/address/del",
            data:{
              id:delet_id,
              user_id:wx.getStorageSync("user_id")
            },
            method:"GET",
            success:function(res){
              console.log(res);
              wx.request({
                url:"https://wx.ichelaba.com/htapi/index.php/user/address/index",
                data:{
                  user_id:wx.getStorageSync("user_id")
                },
                method:"GET",
                success:function(res){
                  console.log(res);
                  self.setData({
                    shuju:res.data.address_list
                  })
                  var have=null;
                  for(var i=0;i<res.data.address_list.length;i++){
                    if(res.data.address_list[i].is_default==1){
                      have=1;
                      self.data.carList=res.data.address_list[i].address_id;
                    }
                  }
                  if(have==null){
                    self.setData({
                      default_id:null
                    }) 
                  }
                  wx.hideLoading();
                }
              })
            }
          })

        }else{

        }
      }
    })
  }
})